<template>
	<view class="ys">
		<view class="no-list" v-if="list.length == 0">
			<image src="/static/index/nolist.png" mode="widthFix"></image>
			- 暂无数据 -
		</view>
		<view class="list" v-else>
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="title" @click="change(item)">
					{{item.name}}
					<uni-icons type="right"></uni-icons>
				</view>
				<view class="toggle" v-if="item.show">
					<view class="nolist" v-if="item.member.length == 0">
						- 暂无成员 -
					</view>
					<view class="member" v-else>
						<view class="mitem" v-for="(m,i) in item.member" :key="i">
							<image :src="m.avatar_path || siteConf.logo" mode=""></image>
							<text>{{m.name}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="add" @click="toPage('./add')">
			<image src="/static/index/add2.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	import {
		getStoreGroup
	} from "@/api/user.js"
	export default {
		data() {
			return {
				list: []
			}
		},
		onShow() {
			this.getStoreGroup()
		},
		methods: {
			change(item) {
				item.show = !item.show
			},
			getStoreGroup() {
				getStoreGroup().then(res => {
					if (res.code == 0) {
						let arr = res.data
						arr.forEach(item => {
							item.show = false
						})
						this.list = arr
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.add {
		position: fixed;
		z-index: 1005;
		right: 0;
		bottom: 10%;

		image {
			width: 60px;
			height: 60px;
		}
	}

	.list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 15px 10px;
		box-sizing: border-box;
		flex-wrap: wrap;

		.item {
			background: #fff;
			border-radius: 6px;
			padding: 10px;
			box-sizing: border-box;
			width: 100%;
			margin-bottom: 15px;
			box-shadow: 0 0 5px #eee;

			.title {
				font-weight: bold;
				padding: 10px 0;
				font-size: 17px;
				display: flex;
				justify-content: space-between;
			}

			.imgbox {
				width: 60px;
				height: 60px;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.member {
				padding-bottom: 20px;
				display: flex;
				flex-wrap: wrap;
				margin-top: 10px;

				.mitem {
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					width: 25%;
				}

				image {
					width: 50px;
					height: 50px;
					border-radius: 50%;
					margin-bottom: 5px;
				}
			}

			.nolist {
				text-align: center;
				padding: 20px 0;
				color: #777;
			}
		}
	}
</style>